var a = getApp();

Page({
    data: {
        heightTop: "",
        show: "",
        loading: !1,
        service_mobile: "",
        service_QRcode: "",
        severShow: !1,
        page: 1,
        startMove: !1,
        touchind: ""
    },
    onLoad: function(t) {
        if (t && this.setData({
            id: t.id,
            ind: t.ind
        }), 0 == t.ind ? this.setData({
            touchind: "-1"
        }) : this.setData({
            touchind: ""
        }), t.scene) {
            var e = decodeURIComponent(t.scene);
            if (e) {
                var i = [];
                i = e.split(",");
                for (var o = 0; o < i.length; o++) {
                    var n;
                    "mid" == (n = i[o].split("="))[0] && a._setMid(n[1]), "id" == n[0] && this.setData({
                        id: n[1]
                    }), "ind" == n[0] && this.setData({
                        ind: n[1]
                    });
                }
            }
        }
        this.getData();
    },
    toAdv: function(t) {
        console.log("跳转到广告", t);
        var e = t.currentTarget.dataset.link;
        if (a._isTextEmpty(e) || !a._isTextEmpty(e)) try {
            wx.navigateTo({
                url: e
            });
        } catch (a) {
            wx.reLaunch({
                url: "/packageG/index/index"
            });
        }
    },
    touchend: function(a) {
        console.log("结束111111111111111111", this.data.ind, a);
        var t = a.changedTouches[0].clientX, e = this.data.clientX_start;
        if (!this.data.touchind) return this.setData({
            touchind: "-1"
        }), void console.log("到达第一个轮播");
        "-1" == this.data.touchind && 0 == this.data.ind && e < t && (console.log("左滑了"), 
        wx.navigateTo({
            url: "/packageH/article/periodicalDetail/periodicalDetail?id=" + this.data.id
        }));
    },
    touchstart: function(a) {
        this.setData({
            clientX_start: a.changedTouches[0].clientX
        });
    },
    bindchangeTap: function(a) {
        var t = this, e = a.detail.current;
        this.setData({
            ind: e
        }), wx.createSelectorQuery().selectAll(".articleBox").boundingClientRect(function(a) {
            t.setData({
                heightTop: a[e].height + "px"
            });
        }).exec();
    },
    onReady: function() {},
    readyAll: function() {
        var a = this;
        setTimeout(function() {
            wx.createSelectorQuery().selectAll(".articleBox").boundingClientRect(function(t) {
                console.log(t, "111111111"), a.setData({
                    heightTop: t[a.data.ind].height + "px"
                }), console.log(t[a.data.ind].height);
            }).exec();
        }, 1e3);
    },
    shareTap: function(a) {
        this.setData({
            show: !0
        });
    },
    shareTapCancel: function(a) {
        this.setData({
            show: !1
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        var a = wx.getStorageSync("yz_uid"), t = "";
        return a && (t = a), {
            title: this.data.article_data[this.data.ind].has_one_article.title,
            path: "/packageH/article/periodicalWatch/periodicalWatch?id=" + this.data.id + "&ind=" + this.data.ind + "&mid=" + t,
            imageUrl: this.data.article_data[this.data.ind].has_one_article.thumb ? this.data.article_data[this.data.ind].has_one_article.thumb : ""
        };
    },
    tapLIst: function(a) {
        console.log(a);
        var t = a.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageH/article/periodicalDetail/periodicalDetail?id=" + t
        });
    },
    toGoBtn: function(a) {
        console.log(a);
        var t = a.currentTarget.dataset.key;
        "home" == t ? wx.reLaunch({
            url: "/packageH/article/periodicalIndex/periodicalIndex"
        }) : "list" == t && wx.redirectTo({
            url: "/packageH/article/periodicalDetail/periodicalDetail?id=" + this.data.id
        });
    },
    severShowTap: function() {
        this.setData({
            severShow: !0
        });
    },
    closePop: function() {
        this.setData({
            severShow: !1
        });
    },
    getData: function() {
        wx.showLoading({
            title: "加载中"
        });
        var t = this, e = a.getNetAddresss("plugin.journal.frontend.journal.detail");
        a._postNetWork({
            url: e,
            data: {
                journal_id: t.data.id,
                page: t.data.page
            },
            success: function(a) {
                var e = a.data;
                wx.hideLoading({
                    success: function(a) {}
                }), 1 == e.result ? (t.setData({
                    article_data: e.data.article_data,
                    before_journal: e.data.before_journal.data,
                    last_page: e.data.before_journal.last_page,
                    current_page: e.data.before_journal.current_page,
                    code: e.data.customer_service.code
                }), "1" == e.data.customer_service.code && (t.setData({
                    service_QRcode: e.data.customer_service.data.service_QRcode,
                    service_mobile: e.data.customer_service.data.service_mobile
                }), console.log(t.data.service_QRcode, t.data.service_mobile)), e.data.before_journal.current_page >= e.data.before_journal.last_page ? t.setData({
                    loading: !1
                }) : t.setData({
                    loading: !0
                }), t.readyAll()) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    taploadMore: function() {
        if (console.log(this.data.current_page, this.data.last_page), this.data.current_page >= this.data.last_page) console.log("没有更多"); else {
            var t = this.data.page + 1;
            this.setData({
                page: t
            }), console.log(this.data.page), wx.showLoading({
                title: "加载中"
            });
            var e = this, i = a.getNetAddresss("plugin.journal.frontend.journal.detail");
            a._postNetWork({
                url: i,
                data: {
                    journal_id: e.data.id,
                    page: e.data.page
                },
                success: function(a) {
                    var t = a.data;
                    wx.hideLoading({
                        success: function(a) {}
                    }), 1 == t.result ? (e.setData({
                        before_journal: e.data.before_journal.concat(t.data.before_journal.data),
                        last_page: t.data.before_journal.last_page,
                        current_page: t.data.before_journal.current_page
                    }), t.data.before_journal.current_page >= t.data.before_journal.last_page ? e.setData({
                        loading: !1
                    }) : e.setData({
                        loading: !0
                    }), e.readyAll()) : wx.showToast({
                        title: t.msg,
                        icon: "none",
                        duration: 1e3
                    });
                },
                fail: function(a) {
                    console.log(a.msg);
                }
            });
        }
    },
    getPoste: function() {
        wx.showLoading({
            title: "加载中"
        });
        var t = this, e = this.data.article_data[this.data.ind].id, i = a.getNetAddresss("plugin.journal.frontend.create-new-poster.createPoster");
        a._postNetWork({
            url: i,
            data: {
                journal_article_id: e,
                article_key: this.data.ind
            },
            success: function(a) {
                var e = a.data;
                wx.hideLoading({
                    success: function(a) {}
                }), 1 == e.result ? t.setData({
                    show: !1,
                    posterImg: e.data,
                    postShow: !0
                }) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1e3
                });
            },
            fail: function(a) {
                console.log(a.msg);
            }
        });
    },
    checkImg: function() {
        var a = [];
        a.push(this.data.posterImg), wx.previewImage({
            urls: a
        });
    },
    onClose: function() {
        this.setData({
            postShow: !1
        });
    }
});